import request from "@/utils/request";
import type { SysDictDataDTO, SysDictDataFiltDTO, SysDictDataVO, SysDictDTO, SysDictFiltDTO, SysDictVO } from "./sysDictType";
import type { IdDTO, PageQueryDTO, PageQueryVO } from "../type/baseType";

enum URL {
    URL_DICT_BASE = '/dict',
    URL_DICT_PAGE = URL_DICT_BASE + '/page',
    URL_DICT_MAP = URL_DICT_BASE + '/map',
    URL_DICT_DATA_BASE = '/dict/data',
    URL_DICT_DATA_PAGE = URL_DICT_DATA_BASE + '/page',
}

/**
 * 增加Dict
 * @param sysDictDTO
 * @returns 
 */
export const addDict = (sysDictDTO: SysDictDTO):
    Promise<undefined> =>
    request.post(URL.URL_DICT_BASE, sysDictDTO)

/**
 * 删除Dict
 * @param id
 * @returns 
 */
export const deleteDict = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_DICT_BASE}/${id.id}`)

/**
 * 修改Dict
 * @param id
 * @param sysDictDTO
 * @returns 
 */
export const updateDict = (id: IdDTO, sysDictDTO: SysDictDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_DICT_BASE}/${id.id}`, sysDictDTO)

/**
 * 分页查询所有Dict列表
 * @param pageQueryDTO
 * @returns 
 */
export const queryDictPage = (pageQueryDTO: PageQueryDTO<SysDictFiltDTO>):
    Promise<PageQueryVO<SysDictVO>> =>
    request.get(URL.URL_DICT_PAGE, {
        params: {
            pageNum: pageQueryDTO.pageNum,
            pageSize: pageQueryDTO.pageSize,
            ...pageQueryDTO.param
        }
    })

/***
 * 查询所有字典
 */
export const queryDictAll = ():
    Promise<Record<string, Record<string, string>>> =>
    request.get(URL.URL_DICT_MAP)

/**
 * 增加DictData
 * @param sysDictDataDTO
 * @returns 
 */
export const addDictData = (sysDictDataDTO: SysDictDataDTO):
    Promise<undefined> =>
    request.post(URL.URL_DICT_DATA_BASE, sysDictDataDTO)

/**
 * 删除DictData
 * @param id
 * @returns 
 */
export const deleteDictData = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_DICT_DATA_BASE}/${id.id}`)

/**
 * 修改DictData
 * @param id
 * @param sysDictDataDTO
 * @returns 
 */
export const updateDictData = (id: IdDTO, sysDictDataDTO: SysDictDataDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_DICT_DATA_BASE}/${id.id}`, sysDictDataDTO)

/**
 * 分页查询所有DictData列表
 * @param pageQueryDTO
 * @param identifier
 * @returns 
 */
export const queryDictDataPage = (pageQueryDTO: PageQueryDTO<SysDictDataFiltDTO>, identifier: string):
    Promise<PageQueryVO<SysDictDataVO>> =>
    request.get(URL.URL_DICT_DATA_PAGE, {
        params: {
            pageNum: pageQueryDTO.pageNum,
            pageSize: pageQueryDTO.pageSize,
            identifier,
            ...pageQueryDTO.param
        }
    })